#ifndef TD_ANIMATIONSET_H
#define TD_ANIMATIONSET_H


/************************************************************************/
/* BOOST                                                                */
/************************************************************************/
#include "boost/smart_ptr/shared_ptr.hpp"

/************************************************************************/
/* STL                                                                  */
/************************************************************************/
#include <vector> 
#include <map>

/************************************************************************/
/* Core                                                                 */
/************************************************************************/
#include "Core/Coord2D.h"
 
/************************************************************************/
/* Game                                                                 */
/************************************************************************/
#include "Game/Animations/Animation.h"

/************************************************************************/
/* Resources                                                            */
/************************************************************************/
#include "Resources/ResourceManager.h"

using namespace boost;


namespace TD_Game {

	/** Encapsulates a set of animations.*/
	class AnimationSet  {
	
	public:

		/************************************************************************/
		/* ctors and dtors														*/
		/************************************************************************/
		
		//Default
		explicit AnimationSet();

		//Copy
		explicit AnimationSet(const AnimationSet &rhs);

		//Assignment
		AnimationSet & operator=(const AnimationSet &rhs);

		//Initialization
		explicit AnimationSet(const string &startingAnimation);

		~AnimationSet();

		/************************************************************************/
		/* Access functions                                                     */
		/************************************************************************/
		inline Animation * const getCurrentAnimation() const {
			
			return(m_pCurrAnimation);
		}

		inline const string & getCurrentAnimationName() const {
			return(m_currAnimationName);
		}

		inline void setCurrentAnimation(const string &animationName) {
			m_currAnimationName = animationName;
			m_pCurrAnimation = getAnimation(m_currAnimationName);
		}

		inline shared_ptr<Tileset> getSprites() const {
			return(m_pSprites);
		}

		inline Animation * getAnimation(const string &animName) {
			map <string, Animation *>::iterator iter;
			iter = m_animationMap.find(animName);
			if(iter != m_animationMap.end()) {
				return(iter->second);
			}
			return(NULL);
		}
		/************************************************************************/
		/* Functionalities                                                      */
		/************************************************************************/

		void render(SDL_Surface *const g_destSurface, unsigned int deltaTime, const Coord2D &offsetPos);

	protected:
		/** The tile set that the animation set will work on*/
		shared_ptr<Tileset> m_pSprites; 

		/** A map of Animations*/
		map <string, Animation *> m_animationMap;

		
		/************************************************************************/
		/* Pure virtual functions                                               */
		/************************************************************************/
		/** This function MUST initialize the m_pSprites pointer and the animation map.*/
		virtual bool initAnimations(unsigned int g_selector) = 0;
		virtual bool initAnimations() { return true;};

		inline void deleteAnimation(const string &animName) {
			Animation *pAnim = getAnimation(animName);
			if(pAnim != NULL) {
				delete pAnim;
			}
		}

	private:

		/** Current animation tile */
		Animation *m_pCurrAnimation;

		/** Current animation name */
		string m_currAnimationName;

		/************************************************************************/
		/* Private functions                                                    */
		/************************************************************************/
		Animation *getAnimation(const string &animName) const;
	};
}

#endif

